   // 自动轮播间隔时间（单位：毫秒）
   var interval = 2000;

   var carousel = document.querySelector('.carousel');
   var carouselInner = carousel.querySelector('.carousel-inner');
   var carouselImages = carouselInner.querySelectorAll('img');
   var carouselIndicators = carousel.querySelector('.carousel-indicators');
   var carouselControls = carousel.querySelector('.carousel-controls');
   var prevButton = carouselControls.querySelector('.prev');
   var nextButton = carouselControls.querySelector('.next');
   var currentIndex = 0;
   var timer;

   function showImage(index) {
       // 隐藏所有图片
       for (var i = 0; i < carouselImages.length; i++) {
           carouselImages[i].classList.remove('active');
       }

       // 显示指定索引的图片
       carouselImages[index].classList.add('active');

       // 更新轮播指示器
       var indicators = carouselIndicators.querySelectorAll('li');
       for (var i = 0; i < indicators.length; i++) {
           indicators[i].classList.remove('active');
       }
       indicators[index].classList.add('active');
   }

   function nextImage() {
       currentIndex = (currentIndex + 1) % carouselImages.length;
       showImage(currentIndex);
   }

   function prevImage() {
       currentIndex = (currentIndex - 1 + carouselImages.length) % carouselImages.length;
       showImage(currentIndex);
   }

   // 点击轮播指示器切换图片
   carouselIndicators.addEventListener('click', function (event) {
       if (event.target.tagName === 'LI') {
           var index = Array.prototype.indexOf.call(carouselIndicators.children, event.target);
           currentIndex = index;
           showImage(currentIndex);
           resetTimer();
       }
   });

   // 点击上一张按钮切换图片
   prevButton.addEventListener('click', function () {
       prevImage();
       resetTimer();
   });

   // 点击下一张按钮切换图片
   nextButton.addEventListener('click', function () {
       nextImage();
       resetTimer();
   });

   function startTimer() {
       timer = setInterval(nextImage, interval);
   }

   function resetTimer() {
       clearInterval(timer);
       startTimer();
   }

   // 初始化轮播图
   showImage(currentIndex);
   startTimer();